5-E
Simple site for the info you need...
  • Add Local Admin
  • Backup Dogecoin Wallet
  • Batch Start Powershell
  • Copy A File(s) To All Users On A PC
  • CPU Load Test
  • Disable Users
  • Email Group Members
  • Email With Powershell
  • Exchange Total Size
  • Export to XLSX
  • Export User Cert
  • Get System Info
  • Import Active Directory Module
  • Last Login For All Computer
  • Last Login For All Users
  • Last Login For Select Users
  • List Domain controllers
  • List Groups (With Count) In Active Directory To TXT
  • List Groups (With Count) In Active Directory To XLSX
  • List Groups For A User(s)
  • List Groups In Active Directory to TXT
  • List Home Directory
  • List Members In A Group(s)
  • Password Generator
  • Ping Test
  • Printer Reset
  • Run A Process Every Few Minutes
  • Search For Files On All Local Drives
  • Show iSCSI Device And Disk Number
  • Uninstall Java

Mass Email Group Members

Have you ever needed to email all members of a group and didnt have a distrobution list for it? Happens all the time (well not really but it happend to me...). This Powershell script does just that. If you have a SMTP server that allows you to send un-authenticated email then changing this for your domain/needs is a snap. Watch out for the info.tmp error log!
CODE:
$groups = get-content input.txt 
import-module ActiveDirectory 
foreach ($group in $groups){ 
$arrMembers = Get-ADGroupMember -Identity $group 
foreach ($member in $arrMembers){ 
$user = Get-ADUser $member -Properties * 
$emailto = $user.mail 
$emailname = $user.GivenName 
$nousers = "No users in $group" 
$sent = "email sent to $emailto about $group" 
$emailerror = "email failed for $emailname" 
[string]$emailbody = "" 
$emailbody = $emailbody + "Hello $emailname, " + "`r`n" 
$emailbody = $emailbody + " " + "`r`n" 
$emailbody = $emailbody + "I see you are a member of the Active Directory Group ""$group"". " + "`r`n" 
$emailbody = $emailbody + " " + "`r`n" 
$emailbody = $emailbody + "How cool is that " + "`r`n"  
$emailbody = $emailbody + " " + "`r`n" 
$emailbody = $emailbody + "Admin Team " + "`r`n" 
$emailbody = $emailbody + "555-555-5555 Office " + "`r`n" 
function sendMail{ 
Write-Host "Sending Email to $user.mail" 
#SMTP server name 
$smtpServer = "SMTPserver.Domain.com" 
#Creating a Mail object 
$msg = new-object Net.Mail.MailMessage 
#Creating SMTP server object 
$smtp = new-object Net.Mail.SmtpClient($smtpServer) 
#Email structure  
$msg.From = "NoReply@Domain.com" 
$msg.ReplyTo = "AdminTeam@Domain.com" 
$msg.To.add("$emailto") 
$msg.subject = "Requesting info about $group" 
$msg.body = $emailbody 
#Sending email  
$smtp.Send($msg) 
} 
If (($user.mail) -ne $Null) { 
Try {sendMail 
$sent >> info.tmp}  
catch {$emailerror >> info.tmp} 
} 
ELSE { 
$nousers >> info.tmp 
} 
} 
} 
Use at your own risk
Input File:
MyDomainGroup
Domain Users
DesktopSupport
Use at your own risk
Download: Email Group Members.zip

Tag(s): Email Powershell


Could you spare a few coins?
Dogecoin - D838u1m9YRdzVVu8CZ1JsR78WHgQmUZSr8
Bitcoin - 13iKLoPXcWEYcGtqCi4UcjGQEs7r6M6LFc
Thank you
  • Home

  • Batch
  • Email
  • Exchange
  • How To
  • Local PC
  • Powershell
  • Security